<template>
  <div>
    <el-card>
      <div class="card-header">
        <h4><strong>参数信息</strong></h4>
      </div>
      <div class="card-body">
        <el-descriptions :column="2" border>
          <el-descriptions-item label="产品名称">{{
            form.name
          }}</el-descriptions-item>
          <el-descriptions-item label="产品编号">{{
            form.number
          }}</el-descriptions-item>
          <el-descriptions-item label="产品类型">
            <y-dict-tag :options="pms_product_type" :value="form.type" />
          </el-descriptions-item>
          <el-descriptions-item label="负责人">{{
            form.owner ? form.owner.label : ""
          }}</el-descriptions-item>
          <el-descriptions-item label="创建人">{{
            form.creator_name
          }}</el-descriptions-item>
          <el-descriptions-item label="创建时间">{{
            form.create_time
          }}</el-descriptions-item>
          <el-descriptions-item label="状态">
            <y-dict-tag :options="sys_enable_disable" :value="form.status" />
          </el-descriptions-item>
        </el-descriptions>
      </div>
    </el-card>
    <br />
    <el-card>
      <div class="card-header">
        <h4><strong>备注信息</strong></h4>
      </div>
      <div class="card-body">
        {{ form.remark }}
      </div>
    </el-card>
    <br />
    <el-card>
      <div class="card-header">
        <h4><strong>删除产品</strong></h4>
      </div>
      <div class="card-body">
        <span>
          如果您删除产品，其相关的模块、迭代、版本、等均为自动删除，请慎重考虑！
        </span>
        <el-button
          type="danger"
          style="float: right"
          @click="handleDelete"
          v-hasPermi="['pms:pro:delete']"
        >
          删除
        </el-button>
      </div>
    </el-card>
  </div>
</template>

<script setup name="ProductInfo">
import { getProduct, delProduct } from "@/api/pms/product";

const { proxy } = getCurrentInstance();
const { pms_product_type, sys_enable_disable } = proxy.useDict(
  "pms_product_type",
  "sys_enable_disable"
);

const id = ref(proxy.$route.params.id);
const form = ref({});

const getInfo = async () => {
  const response = await getProduct(id.value);
  form.value = response.data;
};

const handleDelete = async () => {
  if (
    await proxy.$modal.confirm(
      `是否确认删除定时产品编号为"${form.value.number}"的数据项?`
    )
  ) {
    await delProduct(id.value);
    proxy.getList?.();
    proxy.$modal.msgSuccess("删除成功");
  }
};

onMounted(getInfo);
</script>
